package com.hrzyit.whistle.cases.ui.activity

import android.os.Bundle
import android.support.v4.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Route
import com.hrzyit.base.ui.activity.BaseActivity
import com.hrzyit.provider.routers.RouterPath
import com.hrzyit.whistle.cases.R
import com.hrzyit.whistle.cases.ui.fragment.BaiDuMapFragment
import com.hrzyit.whistle.cases.ui.fragment.RegisterCaseFragment
import com.tbruyelle.rxpermissions2.RxPermissions
import org.jetbrains.anko.toast
import java.util.*

/**
 * 新建案件界面
 * @author YangWei
 * @date 2019/3/25
 */
@Route(path = RouterPath.CasesCenter.PATH_REPORT_CASE)
class ReportCaseActivity: BaseActivity() {

    // Fragment 栈
    private var mStack:Stack<Fragment> = Stack()

    // 新建案件 Fragment
    private val registerCaseFragment: RegisterCaseFragment by lazy {
        RegisterCaseFragment()
    }

    // 定位地图 Fragment
    private val baiDuMapFragment: BaiDuMapFragment by lazy {
        BaiDuMapFragment()
    }

    // 录音 Fragment

    // 初始化 RxPermissions
//    private lateinit var mPermissions:RxPermissions

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_report_case)

        initFragment()
        changeFragment(0)
    }

    /**
     * 初始化Fragment栈管理
     */
    private fun initFragment() {
        val manager = supportFragmentManager.beginTransaction()

        manager.add(R.id.mRegisterCaseContainer,registerCaseFragment,"RegisterCaseFragment")
//        manager.add(R.id.mRegisterCaseContainer,baiDuMapFragment,"BaiDuMapFragment")
        manager.commit()

        mStack.add(registerCaseFragment)
//        mStack.add(baiDuMapFragment)

    }

    /**
     * 切换 Fragment
     */
    private fun changeFragment(position:Int){
        val manager = supportFragmentManager.beginTransaction()
        for (fragment in mStack){
            manager.hide(fragment)
        }

        manager.show(mStack[position])
        manager.commit()
    }

    /**
     * 通过 Tag 切换 Fragment
     */
    private fun changeFragmentByTag(tag:String){
        val manager = supportFragmentManager.beginTransaction()
        for (fragment in mStack){
            manager.hide(fragment)
        }
        val fragment = supportFragmentManager.findFragmentByTag(tag)
        manager.show(fragment)
        manager.commit()
    }

}
